package service

import (
	"context"
	"fmt"
	"video_rpc/basic/config"
	__ "video_rpc/basic/proto"
	"video_rpc/handler/model"
)

type Server struct {
	__.UnimplementedVideoServer
}

func (s *Server) VideoAdd(_ context.Context, in *__.VideoReq) (*__.VideoResp, error) {

	vidoe := model.Video{
		Title:    in.Title,
		Type:     in.Type,
		VideoUrl: in.VideoUrl,
		Label:    in.Label,
		Cover:    in.Cover,
		Status:   in.Status,
	}
	err := vidoe.VideoAdd(config.DB)
	if err != nil {
		return nil, fmt.Errorf("视频添加失败")
	}

	return &__.VideoResp{
		VideoId: int64(vidoe.ID),
	}, nil
}

func (s *Server) ReviewAdd(_ context.Context, in *__.ReviewReq) (*__.ReviewResp, error) {

	review := model.Review{
		VideoId:  int(in.VideoId),
		ReviewId: int(in.ReviewId),
		Result:   in.Result,
		Opinion:  in.Opinion,
	}

	err := review.ReviewAdd(config.DB)
	if err != nil {
		return nil, fmt.Errorf("审核添加失败")
	}

	return &__.ReviewResp{
		ReviewId: int64(review.ID),
	}, nil
}
